package com.zhudeshuai.zhudemolist.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author zhudeshuai
 * @since 16/6/7
 */
public class TimeLineView extends View {


    public static final int TOP = 0;
    public static final int MIDDLE = 1;
    public static final int BOTTOM = 2;

    private int mType = 0;

    private int mCircleHeight = 20;
    private Paint mLinePaint;
    private Paint mCirclrPaint;
    private Context mContext;

    public TimeLineView(Context context) {
        this(context, null);
    }

    public TimeLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }


    private void initView(Context context) {
        mContext = context;
        mLinePaint = new Paint();
        mLinePaint.setColor(context.getResources().getColor(android.R.color.holo_green_dark));
        mLinePaint.setStrokeWidth(5);

        mCirclrPaint = new Paint();
        mCirclrPaint.setColor(context.getResources().getColor(android.R.color.holo_green_dark));
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    }

    @Override
    protected void onDraw(Canvas canvas) {
//        canvas.drawColor(mContext.getResources().getColor(android.R.color.holo_blue_light));
        int width = getWidth();
        int height = getHeight();

        //1.画上面线
        if (mType != TOP)
            canvas.drawLine(width / 2, 0, width / 2, (height - mCircleHeight) / 2, mLinePaint);
        //2.画中间圆
        RectF rectf = new RectF((width - mCircleHeight) / 2,
                (height - mCircleHeight) / 2,
                (width - mCircleHeight) / 2 + mCircleHeight,
                (height - mCircleHeight) / 2 + mCircleHeight);
        canvas.drawOval(rectf, mCirclrPaint);
        //3.画下面线
        if (mType != BOTTOM)
            canvas.drawLine(width / 2, (height - mCircleHeight) / 2 + mCircleHeight
                    , width / 2, height, mLinePaint);
    }
}
